various memory leaks from make leaktest
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 16 Sep 2004 20:16:11 +0000 (20:16 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 16 Sep 2004 20:16:11 +0000 (20:16 +0000)
gpsbabel/defs.h
gpsbabel/filter_vecs.c
gpsbabel/hsa_ndv.c
gpsbabel/magproto.c
gpsbabel/main.c
gpsbabel/mapsource.c
gpsbabel/netstumbler.c
gpsbabel/pcx.c
gpsbabel/tiger.c
gpsbabel/vecs.c

index c59e1f1bb6bbd425775f8d6436b185d3818d9af4..f43d03e896b69d37bca17d3923f7aeffb48265ee 100644 (file)
@@ -384,6 +384,7 @@ void warning(const char *, ...)
        ;
 ff_vecs_t *find_vec(char *, char **);
 void disp_vecs(void);
+void exit_vecs(void);
 void disp_formats(int version);
 void printposn(double c, int is_lat);
 
index 1ff52928dff290ef2a0ab4ff08508d4ca68c3106..1306bb83254852063fa48f5780c95870453b475c 100644 (file)
@@ -132,8 +132,12 @@ find_filter_vec(char *const vecname, char **opts)
 void
 free_filter_vec( filter_vecs_t *fvec )
 {
-       if ( fvec->args && fvec->args->argval && *(fvec->args->argval) ) {
-               xfree(*(fvec->args->argval));
+       arglist_t *ap;
+       
+       if ( fvec->args ) {
+               for ( ap = fvec->args; ap->argstring; ap++) {
+                       if (ap->argval && *ap->argval) xfree(*ap->argval);
+               }
        }
 }
 
index 4fa3a8361c291751654a471a7f891e858eb78fea..7e37a67d26e95a2ededbb656e3f06d974f28e044 100644 (file)
@@ -422,8 +422,10 @@ void readVersion4( FILE* pFile)
                for( Vertex = 0; Vertex < numberOfVerticies; Vertex++)
                {               
                        // read vertex position
-                       if( !readPositionRecord( pFile, &lat2, &lng2, pts2) )
+                       if( !readPositionRecord( pFile, &lat2, &lng2, pts2) ) {
+                               xfree(wpt_tmp);
                                return;
+                       }
 
                        wpt_tmp->longitude = lng2;
                        wpt_tmp->latitude = lat2;
@@ -432,12 +434,16 @@ void readVersion4( FILE* pFile)
 
 
                // read the class name
-               if( !readRecord( pFile, EF_CLNM_REC, className) )
+               if( !readRecord( pFile, EF_CLNM_REC, className) ) {
+                       xfree( wpt_tmp );
                        return;
+               }
 
                // read the attributes name
-               if( !readRecord( pFile, EF_ATTR_REC, attr) )
+               if( !readRecord( pFile, EF_ATTR_REC, attr) ) {
+                       xfree( wpt_tmp );
                        return;
+               }
                getAttr(attr, ATTR_OBJECTNAME, &wpt_tmp->shortname, '\x1f');
                getAttr(attr, ATTR_USRMRK, &wpt_tmp->description, '\x1f');
 
index b3fa7bfaad1dfe1407ef5de406be196c65a966ea..4c94064671f1e6b06028ee1d388e456f1854e34f 100644 (file)
@@ -35,11 +35,11 @@ static void termwrite(char *obuf, int size);
 static void mag_readmsg(void);
 static void mag_handon(void);
 static void mag_handoff(void);
-static void *mkshort_handle;
-static char *deficon;
-static char *bs;
-static char *noack;
-static char *nukewpt;
+static void *mkshort_handle = NULL;
+static char *deficon = NULL;
+static char *bs = NULL;
+static char *noack = NULL;
+static char *nukewpt = NULL;
 static int route_out_count;
 static int waypoint_read_count;
 
index b8b6c4d6937405d3549e6325b7936601db46fe49..78acd8dfeb4c766b38ce52ff216d4946adfc8ea5 100644 (file)
@@ -290,6 +290,7 @@ main(int argc, char *argv[])
 
        waypt_flush_all();
        route_flush_all();
+       exit_vecs();
        exit_filter_vecs();
 
 #ifdef DEBUG_MEM
index 617dafafba943cdf6ea739b704b0d64797b6282b..889905c9fdd661851f7b7bcd3364a150e6f51a72 100644 (file)
@@ -546,7 +546,7 @@ mps_waypoint_r(FILE *mps_file, int mps_ver, waypoint **wpt, unsigned int *mpscla
        int lon;
        int     icon;
 
-       waypoint        *thisWaypoint;
+       waypoint        *thisWaypoint = NULL;
        double  mps_altitude = unknown_alt;
        double  mps_proximity = unknown_alt;
        double  mps_depth = unknown_alt;
@@ -634,7 +634,7 @@ mps_waypoint_r(FILE *mps_file, int mps_ver, waypoint **wpt, unsigned int *mpscla
        /* The following Now done elsewhere since it can be useful to read in and 
          perhaps not add to the list */
        /* waypt_add(thisWaypoint); */
-
+       
        return;
 }
 
@@ -1820,11 +1820,15 @@ mps_read(void)
                                fprintf(stderr,"Lost sync with the file reading waypoint - %s\n", wpt->shortname);
 #endif
                                fseek (mps_file_in, mpsFileInPos + reclen, SEEK_SET);
+                               waypt_free( wpt );
                        }
                        else {
                                /* only add to the "real" list if a "user" waypoint otherwise add to the private list */
                                if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt);
-                               else mps_wpt_q_add(&read_route_wpt_head, wpt);
+                               else {
+                                       mps_wpt_q_add(&read_route_wpt_head, wpt);
+                                       waypt_free( wpt );
+                               }
 #ifdef DUMP_ICON_TABLE
                                printf("\t{  %4u, \"%s\" },\n", icon, wpt->shortname);
 #endif
@@ -1972,6 +1976,7 @@ mps_write(void)
                                   since we're here because the user didn't request waypoints, this should be acceptable */
                                mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass);
                                mps_wpt_q_add(&written_wpt_head, wpt);
+                               waypt_free( wpt );
                                /* now return to the start of the waypoint data to do a "clean" copy */
                                fseek(mps_file_temp, tempFilePos, SEEK_SET);
 
@@ -2003,7 +2008,7 @@ mps_write(void)
                                if (recType == 'W')  {
                                        /* need to be careful that we aren't duplicating a wpt defined from elsewhere */
                                        mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass);
-                                       if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt);
+                                       if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt);else waypt_free(wpt);
                                }
                                else break;
                        }
index 620cb1815dbc327953c8e9a7f2e8968f422f9fe4..5f5dba9af225f1dd00a0a42d3cbfc2a220dc9373 100644 (file)
@@ -30,6 +30,10 @@ static char *nsneicon = "Green Square";
 static char *seicon = "Red Diamond";
 static char *sneicon = "Green Diamond";
 static char *snmac = NULL;
+static char *optnseicon = NULL;
+static char *optnsneicon = NULL;
+static char *optseicon = NULL;
+static char *optsneicon = NULL;
 
 static void    fix_netstumbler_dupes(void);
 
@@ -37,10 +41,10 @@ static void fix_netstumbler_dupes(void);
 
 static
 arglist_t netstumbler_args[] = {
-       {"nseicon", &nseicon, "Non-stealth encrypted icon name", ARGTYPE_STRING },
-       {"nsneicon", &nsneicon, "Non-stealth non-encrypted icon name", ARGTYPE_STRING },
-       {"seicon", &seicon, "Stealth encrypted icon name", ARGTYPE_STRING },
-       {"sneicon", &sneicon, "Stealth non-encrypted icon name", ARGTYPE_STRING },
+       {"nseicon", &optnseicon, "Non-stealth encrypted icon name", ARGTYPE_STRING },
+       {"nsneicon", &optnsneicon, "Non-stealth non-encrypted icon name", ARGTYPE_STRING },
+       {"seicon", &optseicon, "Stealth encrypted icon name", ARGTYPE_STRING },
+       {"sneicon", &optsneicon, "Stealth non-encrypted icon name", ARGTYPE_STRING },
        {"snmac", &snmac, "Shortname is MAC address", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
@@ -48,6 +52,10 @@ arglist_t netstumbler_args[] = {
 static void
 rd_init(const char *fname)
 {
+       nseicon = optnseicon?optnseicon:"Red Square";
+       nsneicon = optnsneicon?optnsneicon:"Green Square";
+       seicon = optseicon?optseicon:"Red Diamond";
+       sneicon = optsneicon?optsneicon:"Green Diamond";
        file_in = xfopen(fname, "r", MYNAME);
 }
 
index c1cf531974c2da72b12af0a53320c8ee606836c4..6ac56afad01f2618a61940a8c680c16cf38c52d8 100644 (file)
 static FILE *file_in;
 static FILE *file_out;
 static void *mkshort_handle;
+static char *optdeficon = NULL;
 static char *deficon = "Waypoint";
 
 #define MYNAME "PCX"
 
 static
 arglist_t pcx_args[] = {
-       {"deficon", &deficon, "Default icon name", ARGTYPE_STRING },
+       {"deficon", &optdeficon, "Default icon name", ARGTYPE_STRING },
        {0, 0, 0, 0}
 };
 
 static void
 rd_init(const char *fname)
 {
+       if ( optdeficon ) {
+               deficon = optdeficon;
+       }
+       else {
+               deficon = "Waypoint";
+       }
        file_in = xfopen(fname, "r", MYNAME);
 }
 
@@ -51,6 +58,12 @@ rd_deinit(void)
 static void
 wr_init(const char *fname)
 {
+       if ( optdeficon ) {
+               deficon = optdeficon;
+       }
+       else {
+               deficon = "Waypoint";
+       }
        file_out = xfopen(fname, "w", MYNAME);
        mkshort_handle = mkshort_new_handle();
 }
index c30109765577c16637522773e17418175712c04c..b717f65bd46232bd2c678ad8fedc14d93dd49138 100644 (file)
@@ -33,16 +33,25 @@ static double maxlat, maxlon, minlat, minlon;
 int rec_cnt;
 static char *nolabels = NULL;
 static char *genurl = NULL;
+static char *suppresswhite = NULL;
+static char *iconismarker = NULL;
+static char *snlen = NULL;
+
 static char *margin  = "15%";
 static char *xpixels = "768";
 static char *ypixels = "768";
-static char *snlen = NULL;
 static char *oldthresh = "14";
 static char *oldmarker  = "redpin";
 static char *newmarker  = "greenpin";
 static char *unfoundmarker  = "bluepin";
-static char *suppresswhite = NULL;
-static char *iconismarker = NULL;
+
+static char *optmargin = NULL;
+static char *optxpixels = NULL;
+static char *optypixels = NULL;
+static char *optoldthresh = NULL;
+static char *optoldmarker = NULL;
+static char *optnewmarker = NULL;
+static char *optunfoundmarker = NULL;
 
 int scalev;
 int short_length;
@@ -65,23 +74,23 @@ arglist_t tiger_args[] = {
                ARGTYPE_BOOL },
        {"genurl", &genurl, "Generate file with lat/lon for centering map.",
                ARGTYPE_OUTFILE },
-       {"margin", &margin, "Margin for map.  Degrees or percentage.",
+       {"margin", &optmargin, "Margin for map.  Degrees or percentage.",
                ARGTYPE_FLOAT},
        {"snlen", &snlen, "Max shortname length when used with -s.",
                ARGTYPE_INT},
-       {"oldthresh", &oldthresh, "Days after which points are considered old.",
+       {"oldthresh", &optoldthresh, "Days after which points are considered old.",
                ARGTYPE_INT},
-       {"oldmarker", &oldmarker, "Marker type for old points.",
+       {"oldmarker", &optoldmarker, "Marker type for old points.",
                ARGTYPE_STRING},
-       {"newmarker", &newmarker, "Marker type for new points.",
+       {"newmarker", &optnewmarker, "Marker type for new points.",
                ARGTYPE_STRING},
        {"suppresswhite", &suppresswhite,
                "Suppress whitespace in generated shortnames", ARGTYPE_BOOL },
-       {"unfoundmarker", &unfoundmarker, "Marker type for unfound points.",
+       {"unfoundmarker", &optunfoundmarker, "Marker type for unfound points.",
                ARGTYPE_STRING},
-       {"xpixels", &xpixels, "Width in pixels of map.",
+       {"xpixels", &optxpixels, "Width in pixels of map.",
                ARGTYPE_INT},
-       {"ypixels", &ypixels, "Height in pixels of map.",
+       {"ypixels", &optypixels, "Height in pixels of map.",
                ARGTYPE_INT},
        {"iconismarker", &iconismarker,
                "The icon description is already the marker", ARGTYPE_BOOL },
@@ -96,6 +105,13 @@ arglist_t tiger_args[] = {
 static void
 rd_init(const char *fname)
 {
+       margin  = optmargin?optmargin:"15%";
+       xpixels = optxpixels?optxpixels:"768";
+       ypixels = optypixels?optypixels:"768";
+       oldthresh = optoldthresh?optoldthresh:"14";
+       oldmarker  = optoldmarker?optoldmarker:"redpin";
+       newmarker  = optnewmarker?optnewmarker:"greenpin";
+       unfoundmarker  = optunfoundmarker?optunfoundmarker:"bluepin";
        file_in = xfopen(fname, "r", MYNAME);
        mkshort_handle = mkshort_new_handle();
 }
@@ -110,6 +126,13 @@ rd_deinit(void)
 static void
 wr_init(const char *fname)
 {
+       margin  = optmargin?optmargin:"15%";
+       xpixels = optxpixels?optxpixels:"768";
+       ypixels = optypixels?optypixels:"768";
+       oldthresh = optoldthresh?optoldthresh:"14";
+       oldmarker  = optoldmarker?optoldmarker:"redpin";
+       newmarker  = optnewmarker?optnewmarker:"greenpin";
+       unfoundmarker  = optunfoundmarker?optunfoundmarker:"bluepin";
        file_out = xfopen(fname, "w", MYNAME);
        thresh_days = strtod(oldthresh, NULL);
 }
index fc66634c1c6700a2b44933d5ae3f7340618f2804..c66f92b732411485d9f4a45b5635490451a86855 100644 (file)
@@ -301,6 +301,24 @@ vecs_t vec_list[] = {
        }
 };
 
+void 
+exit_vecs( void )
+{
+       vecs_t *vec = vec_list;
+       while ( vec->vec ) {
+               arglist_t *ap;
+               if ( vec->vec->args ) {
+                       for ( ap = vec->vec->args; ap->argstring; ap++ ) {
+                               if ( ap->argval && *ap->argval ) {
+                                       xfree(*ap->argval);
+                                       *ap->argval = NULL;
+                               }
+                       }
+               }
+               vec++;
+       }
+}
+
 ff_vecs_t *
 find_vec(char *const vecname, char **opts)
 {
@@ -324,11 +342,8 @@ find_vec(char *const vecname, char **opts)
 
                        if (vec->vec->args) {
                                for (ap = vec->vec->args; ap->argstring; ap++){
-                                       void *av;
-                                       av = get_option(*opts, ap->argstring);
-                                       if (av) {
-                                               *ap->argval = av;
-                                       }
+                                       if ( *ap->argval ) xfree(*ap->argval);
+                                       *ap->argval = get_option(*opts, ap->argstring);
                                }
                        }
                } else {